﻿package com.xuanque.mahjongDice.util
{
	import datas.User;
	import flash.text.TextFieldAutoSize;
	import flash.display.MovieClip;
	
	import com.xuanque.mahjongDice.util.ToolTip;
	
	public class SignalAction
	{
		private var signalMc:MovieClip;
		
		private static var Instance:SignalAction;
		
		public function SignalAction(signal_mc:MovieClip)
		{
			Instance = this;
			signalMc = signal_mc;
		}
		
		/*
		 * 单件类的实例 
		*/
		public static function getInstance():SignalAction{
			return Instance;
		}
		
		
		public function setStaticObjectNull():void{
		    Instance = null;
		}
		
		public function recieveSignal():void {
			
		  var cusTimes:Number = new Date().valueOf();
		  var preTimes:Number = User.getInstance().getCsTime();
		  var delay:int = cusTimes - preTimes;
		  
		  if (!ToolTip.getInstance().getStage()) {
			
		    return;
		  }
		  //trace("delay="+delay); 
		  
		  if (delay <= 300) {
			  
		    displaySignal(5,"网络优良");
		    ToolTip.getInstance().updateInfo(this.signalMc, "网络优良");
			
		  }else if (delay <= 500) {
			  
		    displaySignal(4,"网络良好");
		    ToolTip.getInstance().updateInfo(this.signalMc, "网络良好");
			
		  }else if (delay <= 1000) {
			  
		    displaySignal(3,"网络一般");
		    ToolTip.getInstance().updateInfo(this.signalMc, "网络一般");
			
		  }else if (delay > 1000) {
			  
		    displaySignal(1,"网络很差");
		    ToolTip.getInstance().updateInfo(this.signalMc, "网络很差");
			
		  }
		}
		
		private function displaySignal(num:int,info:String):void {
			
		trace("网络信号 ==="+num);
		signalMc.gotoAndStop(num);
		signalMc._txt.autoSize = TextFieldAutoSize.LEFT;
		signalMc._txt.text = info;
		
		/*
		  for (var i:int = 1; i <= num; i++) {
			  
		    signalMc["sg" + i].visible = true;
		  }
		  for (var j:int = 5; j > num; j--) {
			  
		    signalMc["sg" + j].visible = false;
			
		  }
		  
		*/ 
		
		}
		
		
		
		
	}
}